#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
玩家数据模型
"""


class Player:
    """玩家类"""
    
    def __init__(self):
        """初始化玩家属性"""
        self.health = 100          # 生命值
        self.knowledge = 0         # 知识值
        self.energy = 100          # 精力值
        self.inventory = []        # 背包
        self.score = 0             # 分数
        self.exam_scores = []      # 各科考试成绩
        self.teacher_type = None   # 老师类型
    
    def reset(self):
        """重置玩家状态"""
        self.health = 100
        self.knowledge = 0
        self.energy = 100
        self.inventory = []
        self.score = 0
        self.exam_scores = []
        self.teacher_type = None
    
    def to_dict(self):
        """将玩家对象转换为字典，用于保存游戏"""
        return {
            "health": self.health,
            "knowledge": self.knowledge,
            "energy": self.energy,
            "inventory": self.inventory,
            "score": self.score,
            "exam_scores": self.exam_scores,
            "teacher_type": self.teacher_type
        }
    
    def from_dict(self, data):
        """从字典加载玩家数据"""
        self.health = data.get("health", 100)
        self.knowledge = data.get("knowledge", 0)
        self.energy = data.get("energy", 100)
        self.inventory = data.get("inventory", [])
        self.score = data.get("score", 0)
        self.exam_scores = data.get("exam_scores", [])